/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2024/6/12
 * Time: 14:34
 */

#ifndef CARDUI_H
#define CARDUI_H
#include "Card.h"
#include "Global.h"
using namespace std;
namespace Upgrade {

    class CardUi : public QPushButton
    {
    public:
        CardUi(CardSPtr _card, QWidget *_parent = nullptr);

        CardSPtr Card();

        QSize sizeHint() const override;
        QSize minimumSizeHint() const override;
        int   heightForWidth(int width) const override;
        bool  hasHeightForWidth() const override;

    protected:
        void paintEvent(QPaintEvent *event) override;
    protected:
        // 不做处理，仅传递事件
        void mousePressEvent(QMouseEvent *event) override;
        void mouseReleaseEvent(QMouseEvent *event) override;
        void mouseMoveEvent(QMouseEvent *event) override;
    private:
        void InitState();

    private:
        QSvgRenderer big_renderer_;
        QSvgRenderer small_renderer_;
        QSvgRenderer joker_renderer_;
        QSvgRenderer text_renderer_;

        CardSPtr card_ {nullptr};
    };

    /*class TestBtn : public QWidget
    {
    public:
        TestBtn(QWidget *parent = nullptr) : QWidget(parent)
        {
            // qDebug() << this->sizePolicy();
            setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
            setWindowRole()
        }
        QSize sizeHint() const override
        {
            return {150,heightForWidth(150)};
            // return QPushButton::sizeHint();
        };
        QSize minimumSizeHint() const override
        {
            return {150,heightForWidth(150)};
            // return QPushButton::minimumSizeHint();
        };
        int heightForWidth(int width) const override
        {
            return static_cast<int>(width * 1.0 / 3 * 4);
            // return QPushButton::heightForWidth(width);
        };
        bool hasHeightForWidth() const override
        {
            return true;
            // return QPushButton::hasHeightForWidth();
        };

    protected:
        void paintEvent(QPaintEvent * event) override
        {
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing, true);

            // 获取当前窗口大小
            QRect rect   = this->rect();
            int   width  = rect.width();
            int   height = rect.height();

            // 计算圆角半径（相对于窗口大小）
            int radius = qMin(width, height) / 10;

            // 绘制圆角矩形背景
            QPainterPath path;
            path.addRoundedRect(rect, radius, radius);
            painter.fillPath(path, QColor(255, 255, 255));
            painter.setPen(Qt::black);
            painter.drawPath(path);

            QWidget::paintEvent(event);
        };
    };*/

}// namespace Upgrade

#endif//CARDUI_H
